<?php echo breadcrumb(get_breadcrumb($category->id)) ?>
<?php foreach($categories as $category): ?>
<div class="list box">
	<h1 style="background-color:#<?php echo $category->parent->color ?>">
		<img src="uploads/icon/head/<?php echo $category->parent->image ?>" />
		<span><?php echo $category->name ?></span>
		<a class="more" href="contents/index/<?php echo $category->id ?>">ดูทั้งหมด</a>
		<div class="corner_left"></div>
		<div class="corner_right"></div>
	</h1>
	<ul>
		<?php
					$group[18] = '18,154,122';
					$group[19] = '19,123,155,220';
					$group[20] = '20,156,125';
					$group[21] = '21,157,127,228';
					$group[22] = '22,158';
					$group[23] = '23,159,332';
					if(!empty($group[$category->id]))
					{
						$contents = new Content;
						$contents
						->where("start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and status = 'approve'")
						->where('category_id in ('.$group[$category->id].')')
						->limit(4)
						->order_by('id','desc')
						->get();
					}
					else
					{
						$contents = $category
						->content
						->where("start_date <= date(sysdate()) and (end_date >= date(sysdate()) or end_date = date('0000-00-00')) and status = 'approve'")
						->limit(4)
						->order_by('id','desc')
						->get();
					}
		?>
		<?php foreach($contents as $content): ?>
		<li>
			<?php if($content->url): ?>
			<a target="_blank" href="<?php echo $content->url ?>">
			<?php else: ?>
			<a href="contents/view/<?php echo $content->id ?>">
			<?php endif; ?>
				<img src="uploads/content/thumbnail/<?php echo $content->image ?>" />
				<h2><?php echo $content->title ?></h2>
				<?php if(is_file('uploads/content/download/'.$content->file)): ?>
				<div class="download">
					<label>ลักษณะหนังสือ :</label><span><?php echo $content->book_type->name ?></span><img src="themes/bie/images/btn_download.gif" />
				</div>
				<?php endif ?>
				<p><?php echo $content->intro ?></p>
			</a>
		</li>
		<?php endforeach; ?>
		<div class="clear"></div>
	</ul>
</div>
<?php endforeach; ?>